<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模型训练 - 故障诊断系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('main.index') }}">故障诊断系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('main.index') }}">主页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{{ url_for('training.index') }}">模型训练</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('inference.index') }}">故障诊断</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.index') }}">数据管理</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <div class="container mt-4">
        <div class="row">
            <!-- 数据上传卡片 -->
            <div class="col-md-6 mb-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">上传数据集</h5>
                    </div>
                    <div class="card-body">
                        <form id="upload-form">
                            <div class="mb-3">
                                <label for="file" class="form-label">选择数据文件</label>
                                <input type="file" class="form-control" id="file" accept=".csv,.xlsx,.xls" required>
                                <div class="form-text">支持的文件格式：CSV, Excel</div>
                            </div>
                            <button type="submit" class="btn btn-primary">上传文件</button>
                        </form>
                    </div>
                </div>
            </div>

            <!-- 训练配置卡片 -->
            <div class="col-md-6 mb-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">训练配置</h5>
                    </div>
                    <div class="card-body">
                        <form id="training-form">
                            <div class="mb-3">
                                <label for="dataset" class="form-label">选择数据集</label>
                                <select class="form-select" id="dataset" required>
                                    <option value="">请选择数据集</option>
                                    {% for dataset in datasets %}
                                    <option value="{{ dataset }}">{{ dataset }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="target-column" class="form-label">目标列名</label>
                                <input type="text" class="form-control" id="target-column" required>
                                <div class="form-text">输入包含故障类型的列名</div>
                            </div>
                            <div class="mb-3">
                                <label for="epochs" class="form-label">训练轮数</label>
                                <input type="number" class="form-control" id="epochs" value="10" min="1" required>
                            </div>
                            <button type="submit" class="btn btn-success">开始训练</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- 训练进度卡片 -->
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">训练进度</h5>
                    </div>
                    <div class="card-body">
                        <div id="training-progress" style="display: none;">
                            <div class="progress mb-3">
                                <div class="progress-bar progress-bar-striped progress-bar-animated" 
                                     role="progressbar" style="width: 0%"></div>
                            </div>
                            <div id="training-status" class="alert alert-info">准备开始训练...</div>
                        </div>
                        <div id="training-result" style="display: none;">
                            <div class="alert alert-success">
                                <h6>训练完成</h6>
                                <p>准确率: <span id="accuracy">-</span></p>
                            </div>
                            <div id="training-chart"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="footer mt-5 py-3 bg-light">
        <div class="container text-center">
            <span class="text-muted">故障诊断系统 &copy; 2024</span>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    <script src="{{ url_for('static', filename='js/training.js') }}"></script>
</body>
</html> 